<?php 
if (session_id() == '') {
    session_start();
}
require_once ('../utility/appConsts.php');
class IntroClass {
	
	function printIntroPage() {
		$this->turnOnScreen('1');
		$this->turnOnScreen('2');
		$this->turnOnScreen('3');
	}
	function printNextPageWithRelevantScreen($screenNo) {
		$this->turnOnScreen('1');
		$this->turnOnScreen($screenNo);
		$this->turnOnScreen('3');
	}
	function showHeaderScreen() {
		$appConstants = new appConstsClass();
		$appConstants -> initialize();
		$fileHtmlStart = $_SERVER['DOCUMENT_ROOT'].'/gcminteraction/html/header.html';
		$readHtmlStart = fopen($fileHtmlStart, "r");
		$htmlTxtStart = '';
		$html = '';
		while ($lineHtmlStart = fgets($readHtmlStart,1000)) {
			if (stristr ( $lineHtmlStart, '<!-- css File Path -->' )) {
				$replaceWithTxt = "../css/mycss.css";
				$lineHtmlStart = str_replace ( '<!-- css File Path -->', $replaceWithTxt, $lineHtmlStart );
			} else if (stristr ( $lineHtmlStart, '<!-- logoutstyle -->' )) {
				if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == 'true' ) {
				    $replaceWithTxt = "display:block";
				} else {
					$replaceWithTxt = "display:none";
				}
				$lineHtmlStart = str_replace ( '<!-- logoutstyle -->', $replaceWithTxt, $lineHtmlStart );
			} else if (stristr ( $lineHtmlStart, '<!-- logoutaction -->' )) {
				$replaceWithTxt = "../view/start.php?controlVar=20";
				$lineHtmlStart = str_replace ( '<!-- logoutaction -->', $replaceWithTxt, $lineHtmlStart );
			}
			$html .= $lineHtmlStart;
		}
		echo $html;
	}
	function showSearchScreen() {
		$fileHtmlStart = '';
		$readHtmlStart = '';
		$fileHtmlStart = $_SERVER['DOCUMENT_ROOT'].'/gcminteraction/html/body_search.html';
		$readHtmlStart = fopen($fileHtmlStart, "r");
		$htmlTxtStart = '';
		$html = '';
		while ($lineHtmlStart = fgets($readHtmlStart,1000)) {
			if (stristr ( $lineHtmlStart, '<!-- search URI -->' )) {
				$replaceWithTxt = "../view/start?controlVar=19";
				$lineHtmlStart = str_replace ( '<!-- search URI -->', $replaceWithTxt, $lineHtmlStart );
			}
			$html .= $lineHtmlStart;
		}
		echo $html;
	}
	function showLoginSignUpScreen($screenNo) {
		$fileHtmlStart = '';
		$readHtmlStart = '';
		$fileHtmlStart = $_SERVER['DOCUMENT_ROOT'].'/gcminteraction/html/body.html';
		$readHtmlStart = fopen($fileHtmlStart, "r");
		$htmlTxtStart = '';
		$html = '';
		
		
		while ($lineHtmlStart = fgets($readHtmlStart,1000)) {
			if (stristr ( $lineHtmlStart, '<!-- SCREEN TITLE -->' )) {
				if ($screenNo == 211) {
					$screen = 'Login';
				} else if($screenNo == 311) {
					$screen = 'Sign Up';
				} else if($screenNo == 411) {
					$screen = 'Sign Up Response';
				}
				$replaceWithTxt = "Easy ".$screen." Screen";
				$lineHtmlStart = str_replace ( '<!-- SCREEN TITLE -->', $replaceWithTxt, $lineHtmlStart );
			} else if (stristr ( $lineHtmlStart, '<!-- styleforlogin -->')) {
				if ($screenNo == 211) {
				    $replaceWithTxt = 'display:block;';
				} else {
					$replaceWithTxt = 'display:none;';
				}
				$lineHtmlStart = str_replace ( '<!-- styleforlogin -->', $replaceWithTxt, $lineHtmlStart );
			} else if (stristr ( $lineHtmlStart, '<!-- login url -->')) {
				if ($screenNo == 211) {
				    $replaceWithTxt = '../view/start.php?controlVar=1';
				    $lineHtmlStart = str_replace ( '<!-- login url -->', $replaceWithTxt, $lineHtmlStart );
				} 
				
			} else if (stristr ( $lineHtmlStart, '<!-- username -->')) {
				if ($screenNo == 211) {
				    $replaceWithTxt = $this -> userName;
				} 
				$lineHtmlStart = str_replace ( '<!-- username -->', $replaceWithTxt, $lineHtmlStart );
			}
			else if (stristr ( $lineHtmlStart, '<!-- styleforsignup -->' )) {
				if ($screenNo == 311) {
				    $replaceWithTxt = 'display:block;';
				} else {
					$replaceWithTxt = 'display:none;';
				}
				$lineHtmlStart = str_replace ( '<!-- styleforsignup -->', $replaceWithTxt, $lineHtmlStart );
			} else if (stristr ( $lineHtmlStart, '<!-- signupaction -->' )) {
				if ($screenNo == 311) {
				    $replaceWithTxt = '../view/start.php?controlVar=6';
				}
				$lineHtmlStart = str_replace ( '<!-- signupaction -->', $replaceWithTxt, $lineHtmlStart );
			} else if (stristr ( $lineHtmlStart, '<!-- styleforsignupresponse -->' )) {
				if ($screenNo == 411) {
				    $replaceWithTxt = 'display:block;';
				} else {
					$replaceWithTxt = 'display:none;';
				} 
				$lineHtmlStart = str_replace ( '<!-- styleforsignupresponse -->', $replaceWithTxt, $lineHtmlStart );
			}
			
			$html .= $lineHtmlStart;
		}
		echo $html;
	}
	function turnOnScreen($screenNo) {
		if ($screenNo == '1') {
			$this->showHeaderScreen();
		} else if ($screenNo == '3') {
			$this->showFooterScreen();
		} else if ($screenNo == '2') {
			$this->showSearchScreen();
		}else {
			$this->showLoginSignUpScreen($screenNo);
		}
	}
	function showFooterScreen() {
		$fileHtmlStart = '';
		$readHtmlStart = '';
		$fileHtmlStart = $_SERVER['DOCUMENT_ROOT'].'/gcminteraction/html/footer.html';
		$readHtmlStart = fopen($fileHtmlStart, "r");
		$htmlTxtStart = '';
		$html = '';
		$screen = 'Sign Up';
		while ($lineHtmlStart = fgets($readHtmlStart,1000)) {
			if (stristr ( $lineHtmlStart, '<!-- SCREEN TITLE -->' )) {
				$replaceWithTxt = "Easy ".$screen." Screen";
				$lineHtmlStart = str_replace ( '<!-- SCREEN TITLE -->', $replaceWithTxt, $lineHtmlStart );
			}
			$html .= $lineHtmlStart;
		}
		echo $html;
	}
	function printDashBoard($userId,$userType) {
		$this -> showHeaderScreen();
		if ($userType == '1') {
			$this -> showManagerDashBoard($userId);
		} else if ($userType == '2') {
			$this -> showUserDashBoard($userId);
		} else if ($userType == '3') {
			$this -> showAdminDashBoard($userId);
		}
		$this -> showFooterScreen();
	}
	function showManagerDashBoard($userId) {
		$fileHtmlStart = '';
		$readHtmlStart = '';
		$fileHtmlStart = $_SERVER['DOCUMENT_ROOT'].'/gcminteraction/html/manager_user_dashboard.html';
		$readHtmlStart = fopen($fileHtmlStart, "r");
		$htmlTxtStart = '';
		$html = '';
		$screen = 'Sign Up';
		while ($lineHtmlStart = fgets($readHtmlStart,1000)) {
			if (stristr ( $lineHtmlStart, '<!-- SCREEN TITLE -->' )) {
				$replaceWithTxt = "Easy ".$screen." Screen";
				$lineHtmlStart = str_replace ( '<!-- SCREEN TITLE -->', $replaceWithTxt, $lineHtmlStart );
			}
			$html .= $lineHtmlStart;
		}
		echo $html;
	}
	function showUserDashBoard($userId) {
		$fileHtmlStart = '';
		$readHtmlStart = '';
		$fileHtmlStart = $_SERVER['DOCUMENT_ROOT'].'/gcminteraction/html/normal_user_dashboard.html';
		$readHtmlStart = fopen($fileHtmlStart, "r");
		$htmlTxtStart = '';
		$html = '';
		$screen = 'Sign Up';
		while ($lineHtmlStart = fgets($readHtmlStart,1000)) {
			if (stristr ( $lineHtmlStart, '<!-- SCREEN TITLE -->' )) {
				$replaceWithTxt = "Easy ".$screen." Screen";
				$lineHtmlStart = str_replace ( '<!-- SCREEN TITLE -->', $replaceWithTxt, $lineHtmlStart );
			}
			$html .= $lineHtmlStart;
		}
		echo $html;
	}
	function showAdminDashBoard($userId) {
		$fileHtmlStart = '';
		$readHtmlStart = '';
		$fileHtmlStart = $_SERVER['DOCUMENT_ROOT'].'/gcminteraction/html/admin_user_dashboard.html';
		$readHtmlStart = fopen($fileHtmlStart, "r");
		$htmlTxtStart = '';
		$html = '';
		$screen = 'Sign Up';
		while ($lineHtmlStart = fgets($readHtmlStart,1000)) {
			if (stristr ( $lineHtmlStart, '<!-- SCREEN TITLE -->' )) {
				$replaceWithTxt = "Easy ".$screen." Screen";
				$lineHtmlStart = str_replace ( '<!-- SCREEN TITLE -->', $replaceWithTxt, $lineHtmlStart );
			}
			$html .= $lineHtmlStart;
		}
		echo $html;
	}
}
?>